package com.example.rg1activitydemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    public static final String TAG="MainActivity";
    private Button button1;
    private Button buttonBd;
    private Button buttonMe;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG,"onCreate... ...");
        button1=findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //显式切换
                //Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                //startActivity(intent);
                //隐式切换
                Intent intent=new Intent();
                intent.setAction("sd.intent.action.Second");
                intent.addCategory("sd.intent.category.Second");
                startActivity(intent);
            }
        });

        buttonBd=findViewById(R.id.buttonBaidu);
        buttonBd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentBd=new Intent();
                intentBd.setAction("android.intent.action.VIEW");
                intentBd.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intentBd);

            }
        });

        buttonMe=findViewById(R.id.buttonMe);
        buttonMe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentMe=new Intent(MainActivity.this,MainActivity.class);
                startActivity(intentMe);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG,"onStart... ...");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG,"onRestart... ...");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG,"onResume... ...");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG,"onPause... ...");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG,"onStop... ...");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG,"onDestory... ...");
    }


}
